<!--
 * @Author: Harry
 * @Date: 2021-05-06 14:15:41
 * @LastEditTime: 2021-05-06 14:15:41
 * @LastEditors: Harry
 * @Description:
 * @FilePath: \resourcesd:\vscode\ygboost-eui\src\components\app\blank\waybill\waybillmerge\updateExcelFormat.vue
 * @可以输入预定的版权声明、个性签名、空行等
-->
<template>
  <div class="padding-lr-xl ">
    <el-card>
      <div slot="header" class="clearfix text-left">
        <span class="title-icon">基础配置</span>
      </div>
      <el-form :model="form" ref="statisticsConfigurationsForm" size="mini">
             <!-- <el-checkbox-group size="mini" v-model="form"> -->
            <el-form-item
              label="合并变量统计（美线）"
              label-width="140px"
              prop="usa"
            >
              <el-checkbox-group  v-model="form.packagesUsa">
                <el-checkbox :label="1" >件数</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.weightUsa">
                <el-checkbox :label="1" >重量</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.volumeUsa">
                <el-checkbox :label="1" >体积</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.transporttimeUsa">
                <el-checkbox :label="1" >转运时间</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.signfortimeUsa">
                <el-checkbox :label="1" >签收时间</el-checkbox>
              </el-checkbox-group>


            </el-form-item>
            <el-form-item
                      label="合并变量统计（加线）"
                      label-width="140px"
                      prop="europe"
                    >
              <el-checkbox-group  v-model="form.packagesEurope">
                <el-checkbox :label="1" >件数</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.weightEurope">
                <el-checkbox :label="1" >重量</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.volumeEurope">
                <el-checkbox :label="1" >体积</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.transporttimeEurope">
                <el-checkbox :label="1" >转运时间</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.signfortimeEurope">
                <el-checkbox :label="1" >签收时间</el-checkbox>
              </el-checkbox-group>
          </el-form-item>
          <el-form-item
          label="合并变量统计（欧线）"
          label-width="140px"
          prop="canada"
        >
              <el-checkbox-group  v-model="form.packagesCanada">
                <el-checkbox :label="1" >件数</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.weightCanada">
                <el-checkbox :label="1" >重量</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.volumeCanada">
                <el-checkbox :label="1" >体积</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.transporttimeCanada">
                <el-checkbox :label="1" >转运时间</el-checkbox>
              </el-checkbox-group>
              <el-checkbox-group  v-model="form.signfortimeCanada">
                <el-checkbox :label="1" >签收时间</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          <!-- </el-checkbox-group> -->
      </el-form>
    </el-card>
     <div slot="footer" class="dialog-footer">
        <el-button
          size="mini"
          type="primary"
          @click="saveSaleUpdateReceive()"
          >确定</el-button
        >
      </div>
  </div>
</template>

<script>
import { m } from "@/store/yg/common/local";
import { ajax } from "@/store/yg/common/utils";
const Tinymce = () => import("@/components/app/components/Tinymce");
export default {
  components: {
    Tinymce
  },
  data() {
    return {
      form: {
        id:"",
        packagesUsa: "",
        weightUsa: "",
        volumeUsa: "",
        transporttimeUsa: "",
        signfortimeUsa: "",

        packagesEurope: "",
        weightEurope: "",
        volumeEurope: "",
        transporttimeEurope: "",
        signfortimeEurope: "",

        packagesCanada: "",
        weightCanada: "",
        volumeCanada: "",
        transporttimeCanada: "",
        signfortimeCanada: "",
        cuser:parseInt(this.$store.state.auth.user.id),
      },
      statisticsConfigurations:[],
      isChecked:true,
      attrs: {
        class: "com.tofba.app.client.seaair.StatisticsConfigurationClient",
        uri: "/open/message",
        type: "blank"
      },
    };
  },
  mounted() {
    this.init();
  },

  methods: {
    async init() {
      console.log(parseInt(this.$store.state.auth.user.id));
      const statisticsConfigurations = await ajax("findStatisticsConfigurationByUserId", {cuser:parseInt(this.$store.state.auth.user.id)});
      // ajax("findStatisticsConfigurationByUserId", {cuser:parseInt(this.$store.state.auth.user.id)}).then(
      //   res => {
      //     // debugger;
      //     if (!res) {
      //       this.$message.error(res.message);
      //     }
      //   },
      //   error => {
      //     console.log(error);
      //   }
      // );
    if (statisticsConfigurations) {
      this.form = statisticsConfigurations;
      console.log(
        "%cthis.form.id: ",
        "color: MidnightBlue; background: Aquamarine;",
        this.form
      );
      this.form.packagesUsa = [this.form.packagesUsa];
      this.form.weightUsa = [this.form.weightUsa];
      this.form.volumeUsa = [this.form.volumeUsa];
      this.form.transporttimeUsa = [this.form.transporttimeUsa];
      this.form.signfortimeUsa = [this.form.signfortimeUsa];

      this.form.packagesEurope = [this.form.packagesEurope];
      this.form.weightEurope = [this.form.weightEurope];
      this.form.volumeEurope = [this.form.volumeEurope];
      this.form.transporttimeEurope = [this.form.transporttimeEurope];
      this.form.signfortimeEurope = [this.form.signfortimeEurope];

      this.form.packagesCanada = [this.form.packagesCanada];
      this.form.weightCanada = [this.form.weightCanada];
      this.form.volumeCanada = [this.form.volumeCanada];
      this.form.transporttimeCanada = [this.form.transporttimeCanada];
      this.form.signfortimeCanada = [this.form.signfortimeCanada];

    }else{
      this.$message.error("系统异常");
    }
    },
    m(k) {
      return m(k);
    },
      // 弹窗隐藏
    editReceiveDialogClose() {
      this.editReceiveDialog = false;
    },
    // 保存设置
    async saveSaleUpdateReceive()
    {
      console.log(this.form);
      debugger;
      if(this.form.packagesUsa.length===0){
         this.form.packagesUsa =  Number(0);
      }else{
          this.form.packagesUsa = this.form.packagesUsa.length===2?this.form.packagesUsa[1]:this.form.packagesUsa[0];
      }
      if(this.form.weightUsa.length===0){
          this.form.weightUsa = Number(0);
      }else{
          this.form.weightUsa = this.form.weightUsa.length===2?this.form.weightUsa[1]:this.form.weightUsa[0];
      }
      if(this.form.volumeUsa.length===0){
          this.form.volumeUsa = Number(0);
      }else{
          this.form.volumeUsa = this.form.volumeUsa.length===2?this.form.volumeUsa[1]:this.form.volumeUsa[0];
      }
      if(this.form.transporttimeUsa.length===0){
          this.form.transporttimeUsa = Number(0);
      }else{
          this.form.transporttimeUsa = this.form.transporttimeUsa.length===2?this.form.transporttimeUsa[1]:this.form.transporttimeUsa[0];
      }
      if(this.form.signfortimeUsa.length===0){
          this.form.signfortimeUsa = Number(0);
      }else{
          this.form.signfortimeUsa = this.form.signfortimeUsa.length===2?this.form.signfortimeUsa[1]:this.form.signfortimeUsa[0];
      }
      if(this.form.packagesEurope.length===0){
          this.form.packagesEurope = Number(0);
      }else{
          this.form.packagesEurope = this.form.packagesEurope.length===2?this.form.packagesEurope[1]:this.form.packagesEurope[0];
      }
      if(this.form.weightEurope.length===0){
          this.form.weightEurope = Number(0);
      }else{
          this.form.weightEurope = this.form.weightEurope.length===2?this.form.weightEurope[1]:this.form.weightEurope[0];
      }
      if(this.form.volumeEurope.length===0){
          this.form.volumeEurope = Number(0);
      }else{
          this.form.volumeEurope = this.form.volumeEurope.length===2?this.form.volumeEurope[1]:this.form.volumeEurope[0];
      }
      if(this.form.transporttimeEurope.length===0){
          this.form.transporttimeEurope = Number(0);
      }else{
          this.form.transporttimeEurope = this.form.transporttimeEurope.length===2?this.form.transporttimeEurope[1]:this.form.transporttimeEurope[0];
      }
      if(this.form.signfortimeEurope.length===0){
          this.form.signfortimeEurope = Number(0);
      }else{
          this.form.signfortimeEurope = this.form.signfortimeEurope.length===2?this.form.signfortimeEurope[1]:this.form.signfortimeEurope[0];
      }
      if(this.form.packagesCanada.length===0){
          this.form.packagesCanada = Number(0);
      }else{
          this.form.packagesCanada = this.form.packagesCanada.length===2?this.form.packagesCanada[1]:this.form.packagesCanada[0];
      }
      if(this.form.weightCanada.length===0){
          this.form.weightCanada = Number(0);
      }else{
          this.form.weightCanada = this.form.weightCanada.length===2?this.form.weightCanada[1]:this.form.weightCanada[0];
      }
      if(this.form.volumeCanada.length===0){
          this.form.volumeCanada = Number(0);
      }else{
           this.form.volumeCanada = this.form.volumeCanada.length===2?this.form.volumeCanada[1]:this.form.volumeCanada[0];
      }
      if(this.form.transporttimeCanada.length===0){
          this.form.transporttimeCanada = Number(0);
      }else{
          this.form.transporttimeCanada = this.form.transporttimeCanada.length===2?this.form.transporttimeCanada[1]:this.form.transporttimeCanada[0];
      }
      if(this.form.signfortimeCanada.length===0){
          this.form.signfortimeCanada = Number(0);
      }else{
           this.form.signfortimeCanada = this.form.signfortimeCanada.length===2?this.form.signfortimeCanada[1]:this.form.signfortimeCanada[0];
      }


      console.log(this.form);

      let res = await ajax("save", this.form,this.attrs);
      console.log(res);
      if (res.code == 200) {
        this.$message.success("设置成功");
        setTimeout(function() {
            location.reload();
          }, 1500);
      } else {
        this.$message.error(m(`${res.message}`));
      }
    },
  },
};
</script>

<style scoped>
.el-select {
  width: 100%;
}
.padding-lr-xl >>> .el-dialog__header {
  text-align: left;
}
</style>
